import os.path

import visualdl
from visualdl.server import app
from visualdl import LogReader

from src.config.config import EXP_DIR, MODEL_PATH

if __name__ == '__main__':
    reader = LogReader(file_path=os.path.join(EXP_DIR, 'vdlrecords.1740412735.log'))

    # 获取所有标签（按数据类型分类）
    tags = reader.get_tags()
    print("所有标签分类:", tags)

    # 遍历每个数据类型（如 scalar/image/histogram）
    for category in tags:
        print(f"\n=== 数据类型: {category} ===")

        # 遍历该类型下的所有标签
        for tag_name in tags[category]:
            print(f"\n标签名: {tag_name}")

            # 获取该标签下的全部数据记录
            records = reader.get_data(category, tag_name)

            # 逐条输出数据
            for record in records:
                print(record)

    # visualdl.server.app.run(EXP_DIR,
    #                         model=MODEL_PATH,
    #                         host="127.0.0.1",
    #                         port=8040,
    #                         cache_timeout=20,
    #                         language='en',
    #                         public_path=None,
    #                         api_only=False,
    #                         open_browser=False)
    # app.run(
    #     logdir=EXP_DIR,
    #     host="0.0.0.0",  # 允许外部访问
    #     port=8040,
    #     open_browser=True  # 自动打开浏览器
    # )
